One disadvantage of using 3rd party components from a tutorial perspective is that we need to carefully configure our build system to find the libraries. We may also need to copy library files (.dlls) or resources into specific in order that they can be used. You may have already encountered this in the first year with SDL/SDL2 or with OpenGL in Real-time Graphics. We're going to use CMake to get around both these problems an allow us to work anywhere by simply cloning our project and re-running cmake to generate our build environment.
The process:
We started with a base project which included Ogre now we're adding bullet Bullet.
The Ogre with Bullet Base Project is here. Again I'm hoping to add branches from this master project which provide examples for collision detection, ray tracing etc.
Though the Bitbucket Dashboard create a fork of the above repository, the fork option is not obvious. You'll click the + and select Fork the rest of the process is just like creating a new repository (and should be familiar).
Make sure you in the directory you want to store you're working version of the project. Open GitBash and use this to clone your repository.
> git clone ...
In explorer navigate to the directory into which you've cloned your project and inside the o3d_1-14_bull_3_base directory create a build directory.
We'll use the CMake-Gui (as we have for Ogre and Bullet), the makes configuring CMake to find Ogre much easier. Make sure you have Grouped checked!
Here's the options to change, I've included the full list at the end but hopefully you won't need it!
| Description | Group | Key | Value |
|---|---|---|---|
| Location of the Ogre SDK | CMAKE | OGRE_DIR | <where you cloned>/build/sdk/CMake |
The image above shows my configuration for the base project. Set the OGRE_DIR to the SDK path, this should be <where you cloned>/ogre/build/sdk/CMake your path will start differently to mine but should end the same unless you changed the SDK output directory when configuring Ogre.
BULLET_ROOT is not an existing parameter, its an optional one used if bullet is not installed in a standard location. We'll be setting bullet root to the sdk directory we created as an output directory when we compiled bullet. To do this we click Add Entry, this brings up a dialogue asking for the name, type and value.
Name: BULLET_ROOT
Type: Path
Value: <path-to-bullet>/bullet/build/sdk
Configure CMake and Generate the a Visual Studio project.
Change the start up project to SimpleGame, then Build the project (select Build from the Build menu).
You will need to build the install target, this is not a real target but runs a build script. This copies the executable and the required configuration files, link libraries etc. to a sub-location in the build library.
Ogre3d relies on a number of config files and media files being present. To ease development placed these in a directory called dist the install step copies these into the build directory and place it with the executable. You may note that there is no .dll for Bullet, this is correct. Bullet is a static library so when it is linked against our game it is built into the executable.
You should have the following file structure:
dist
├── bin
│ ├── resources.cfg
│ └── SimpleGame
└── media
├── materials
│ ├── scripts
│ │ ├── Examples.material
│ │ └── Ogre.material
│ └── textures
│ ├── GreenSkin.jpg
│ ├── nskingr.jpg
│ ├── rockwall.tga
│ ├── spheremap.png
│ └── tusk.jpg
├── models
│ ├── cube.mesh
│ ├── ninja.mesh
│ ├── ninja.skeleton
│ └── ogrehead.mesh
└── packs
└── SdkTrays.zip
The media directories are mostly for later tutorials which require loaded models. Packs are actually zip files as Ogre supports the loading of resources from one or more archives.
CMake can set custom properties on different operating systems, in the case of Windows I've set a variable used by Visual Studio to identify its runtime library. As a result it should be possible to just run/debug as normal.
Here are all the other options, there should only be two we need to set. But I'm proving a full list in case you need to double check your setup. I've made the ones we set bold, with these set CMake should be able to populate the rest.
BULLET Group of Options
| Description | Group | Key | Value |
|---|---|---|---|
| Path to Bullet SDK (we added) | BULLET | BULLET_ROOT | <where-you-put-bullet>\bullet3\build\sdk |
| Path to a library. | BULLET | BULLET_COLLISION_LIBRARY | <where-you-put-bullet>/bullet3/build/sdk/lib/BulletCollision.lib |
| Path to a library | BULLET | BULLET_COLLISION_LIBRARY_DEBUG | BULLET_COLLISION_LIBRARY_DEBUG-NOTFOUND |
| Path to a library. | BULLET | BULLET_DYNAMICS_LIBRARY | <where-you-put-bullet>/bullet3/build/sdk/lib/BulletDynamics.lib |
| Path to a library. | BULLET | BULLET_DYNAMICS_LIBRARY_DEBUG | BULLET_DYNAMICS_LIBRARY_DEBUG-NOTFOUND |
| Path to a file. | BULLET | BULLET_INCLUDE_DIR | <where-you-put-bullet>/bullet3/build/sdk/include/bullet |
| Path to a library. | BULLET | BULLET_MATH_LIBRARY | <where-you-put-bullet>/bullet3/build/sdk/lib/LinearMath.lib |
| Path to a library. | BULLET | BULLET_MATH_LIBRARY_DEBUG | BULLET_MATH_LIBRARY_DEBUG-NOTFOUND |
| Path to a library. | BULLET | BULLET_SOFTBODY_LIBRARY | <where-you-put-bullet>/bullet3/build/sdk/lib/BulletSoftBody.lib |
| Path to a library. | BULLET | BULLET_SOFTBODY_LIBRARY_DEBUG | BULLET_SOFTBODY_LIBRARY_DEBUG-NOTFOUND |
CMAKE Group of Options
| Description | Group | Key | Value |
|---|---|---|---|
| Path to a program. | CMAKE | CMAKE_AR | C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/lib.exe |
| Semicolon separated list of supported configuration types, only supports Debug, Release, MinSizeRel, and RelWithDebInfo, anything else will be ignored. |
CMAKE | CMAKE_CONFIGURATION_TYPES | Debug;Release;MinSizeRel;RelWithDebInfo |
| Flags used by the CXX compiler during all build types. | CMAKE | CMAKE_CXX_FLAGS | /DWIN32 /D_WINDOWS /W3 /GR /EHsc |
| Flags used by the CXX compiler during DEBUG builds. | CMAKE | CMAKE_CXX_FLAGS_DEBUG | /MDd /Zi /Ob0 /Od /RTC1 |
| Flags used by the CXX compiler during MINSIZEREL builds. | CMAKE | CMAKE_CXX_FLAGS_MINSIZEREL | /MD /O1 /Ob1 /DNDEBUG |
| Flags used by the CXX compiler during RELEASE builds. | CMAKE | CMAKE_CXX_FLAGS_RELEASE | /MD /O2 /Ob2 /DNDEBUG |
| Flags used by the CXX compiler during RELWITHDEBINFO builds. | CMAKE | CMAKE_CXX_FLAGS_RELWITHDEBINFO | /MD /Zi /O2 /Ob1 /DNDEBUG |
| Libraries linked by default with all C++ applications. | CMAKE | CMAKE_CXX_STANDARD_LIBRARIES | kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib |
| Flags used by the C compiler during all build types. | CMAKE | CMAKE_C_FLAGS | /DWIN32 /D_WINDOWS /W3 |
| Flags used by the C compiler during DEBUG builds. | CMAKE | CMAKE_C_FLAGS_DEBUG | /MDd /Zi /Ob0 /Od /RTC1 |
| Flags used by the C compiler during MINSIZEREL builds. | CMAKE | CMAKE_C_FLAGS_MINSIZEREL | /MD /O1 /Ob1 /DNDEBUG |
| Flags used by the C compiler during RELEASE builds. | CMAKE | CMAKE_C_FLAGS_RELEASE | /MD /O2 /Ob2 /DNDEBUG |
| Flags used by the C compiler during RELWITHDEBINFO builds. | CMAKE | CMAKE_C_FLAGS_RELWITHDEBINFO: | /MD /Zi /O2 /Ob1 /DNDEBUG |
| Libraries linked by default with all C applications. | CMAKE | CMAKE_C_STANDARD_LIBRARIES | kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib |
| Flags used by the linker during all build types. | CMAKE | CMAKE_EXE_LINKER_FLAGS | /machine:x64 |
| Flags used by the linker during DEBUG builds. | CMAKE | CMAKE_EXE_LINKER_FLAGS_DEBUG | /debug /INCREMENTAL |
| Flags used by the linker during MINSIZEREL builds. | CMAKE | CMAKE_EXE_LINKER_FLAGS_MINSIZEREL | /INCREMENTAL:NO |
| Flags used by the linker during RELEASE builds. | CMAKE | CMAKE_EXE_LINKER_FLAGS_RELEASE | /INCREMENTAL:NO |
| Flags used by the linker during RELWITHDEBINFO builds. | CMAKE | CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO | /debug /INCREMENTAL |
| Install path prefix, prepended onto install directories. | CMAKE | CMAKE_INSTALL_PREFIX | C:/Program Files (x86)/OgreBaseProject |
| Path to a program. | CMAKE | CMAKE_LINKER | C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/link.exe |
| Flags used by the linker during the creation of modules during all build types. |
CMAKE | CMAKE_MODULE_LINKER_FLAGS | /machine:x64 |
| Flags used by the linker during the creation of modules during DEBUG builds. |
CMAKE | CMAKE_MODULE_LINKER_FLAGS_DEBUG | /debug /INCREMENTAL |
| Flags used by the linker during the creation of modules during MINSIZEREL builds. |
CMAKE | CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL | /INCREMENTAL:NO |
| Flags used by the linker during the creation of modules during RELEASE builds. |
CMAKE | CMAKE_MODULE_LINKER_FLAGS_RELEASE | /INCREMENTAL:NO |
| Flags used by the linker during the creation of modules during RELWITHDEBINFO builds. |
CMAKE | CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO | /debug /INCREMENTAL |
| Path to a program. | CMAKE | CMAKE_MT | CMAKE_MT-NOTFOUND |
| RC compiler | CMAKE | CMAKE_RC_COMPILER | rc |
| Flags for Windows Resource Compiler during all build types. | CMAKE | CMAKE_RC_FLAGS | -DWIN32 |
| Flags for Windows Resource Compiler during DEBUG builds. | CMAKE | CMAKE_RC_FLAGS_DEBUG | -D_DEBUG |
| Flags for Windows Resource Compiler during MINSIZEREL builds. | CMAKE | CMAKE_RC_FLAGS_MINSIZEREL | |
| Flags for Windows Resource Compiler during RELEASE builds. | CMAKE | CMAKE_RC_FLAGS_RELEASE: | |
| Flags for Windows Resource Compiler during RELWITHDEBINFO builds. | CMAKE | CMAKE_RC_FLAGS_RELWITHDEBINFO | |
| Flags used by the linker during the creation of shared libraries during all build types. |
CMAKE | CMAKE_SHARED_LINKER_FLAGS | /machine:x64 |
| Flags used by the linker during the creation of shared libraries during DEBUG builds. |
CMAKE | CMAKE_SHARED_LINKER_FLAGS_DEBUG | /debug /INCREMENTAL |
| Flags used by the linker during the creation of shared libraries during MINSIZEREL builds. |
CMAKE | CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL | /INCREMENTAL:NO |
| Flags used by the linker during the creation of shared libraries during RELEASE builds. |
CMAKE | CMAKE_SHARED_LINKER_FLAGS_RELEASE | /INCREMENTAL:NO |
| Flags used by the linker during the creation of shared libraries during RELWITHDEBINFO builds. |
CMAKE | CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO | /debug /INCREMENTAL |
| If set, runtime paths are not added when installing shared libraries, but are added when building. |
CMAKE | CMAKE_SKIP_INSTALL_RPATH | OFF |
| If set, runtime paths are not added when using shared libraries. | CMAKE | CMAKE_SKIP_RPATH | OFF |
| Flags used by the linker during the creation of static libraries during all build types. |
CMAKE | CMAKE_STATIC_LINKER_FLAGS | /machine:x64 |
| Flags used by the linker during the creation of static libraries during DEBUG builds. |
CMAKE | CMAKE_STATIC_LINKER_FLAGS_DEBUG | |
| Flags used by the linker during the creation of static libraries during MINSIZEREL builds. |
CMAKE | CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL | |
| Flags used by the linker during the creation of static libraries during RELEASE builds. |
CMAKE | CMAKE_STATIC_LINKER_FLAGS_RELEASE | |
| Flags used by the linker during the creation of static libraries during RELWITHDEBINFO builds. |
CMAKE | CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO | |
| If this value is on, makefiles will be generated without the .SILENT directive, and all commands will be echoed to the console during the make. This is useful for debugging only. With Visual Studio IDE projects all commands are done without /nologo. |
CMAKE | CMAKE_VERBOSE_MAKEFILE | OFF |
Ogre Group
| Description | Group | Key | Value |
|---|---|---|---|
| The directory containing a CMake configuration file for OGRE. | OGRE | OGRE_DIR | <path-to-ogre>/ogre/build/sdk/CMake |